#!/usr/bin/node

const log = console.log;
const koa = require('koa');

let app = new koa();

//加载使用中间件

//M-logger
app.use(async (ctx, next)=>{
  log(`${ctx.method} ${ctx.url}`);

  //加载下一个中间件
  //next前面是请求的解析，后面是响应的封装
  const cost = await next();
  log('cost:'+cost+'ms');
})

//M-ms
app.use((ctx,next)=>{
  const start = Date.now();
  next();
  const end = Date.now();
  return end-start; 
})

//M-hello
app.use((ctx,next)=>{
  //requset parse
  //make response
  ctx.body='hello koa';
});



app.listen(3000);

log('hello world');

